<template>
    <view class="container">
        <view class="list-item" @click="handleItemClick({url:'/pages/printerSet/printerSet'})">
            <view class="title">打印配置</view>
            <view class="note">配置打印机参数</view>
        </view>
        <view class="list-item" @click="handleItemClick({url:'exit'})">
            <view class="title">退出</view>
            <view class="note">用户请勿点击，由管理员需验证后退出</view>
        </view>
<!--        <view v-for="(item, index) in itemList" :key="index" class="list-item" @click="handleItemClick(item)">-->
<!--            <view class="title">{{ item.title }}</view>-->
<!--            <view class="note">{{ item.note }}</view>-->
<!--        </view>-->
    </view>
</template>

<script>
const printerModule = uni.requireNativePlugin("PrinterModule")

export default {
    data() {
        return {
            itemList: [
                { title: '打印配置', note: '配置打印机参数', url: '/pages/printerSet/printerSet' },
                { title: '退出', note: '用户请勿点击，由管理员需验证后退出', url: 'exit' },
            ]
        }
    },
    methods: {
        handleItemClick(item) {
            if (item.url === 'exit') {
                // 弹出密码输入框，输入密码
                uni.showModal({
                    title: '请输入密码',
                    content: '',
                    showCancel: false,
                    editable: true, // 开启编辑框
                    success: (res) => {
                        if (res.confirm) {
                            const password = res.content.trim(); // 获取输入的密码
                            if (password === '13888745525') {
                                printerModule.exit(); // 执行退出操作
                                uni.showToast({
                                    title: '退出成功',
                                    icon: 'success'
                                });
                            } else {
                                uni.showToast({
                                    title: '密码错误',
                                    icon: 'none'
                                });
                            }
                        }
                    }
                });
            } else {
                // 如果是其他项，则跳转页面
                uni.navigateTo({
                    url: item.url
                });
            }
        }
    }
}
</script>

<style>
.container {
    padding: 10px;
}

.list-item {
    padding: 15px;
    border: 1px solid #ddd;
    margin-bottom: 10px;
    background-color: #fff;
}

.title {
    font-size: 18px;
    font-weight: bold;
}

.note {
    font-size: 14px;
    color: #888;
}
</style>
